package com.briup.web02.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Map;

@RestController
public class RequestController {

    @RequestMapping("/showRequest")
    public String  showRequest(HttpServletRequest request){
        System.out.println(request.getClass());
        return  "光宗耀组";
    }

    @RequestMapping("/getMessage")
    public String  getMessage(HttpServletRequest request){
        String protocol = request.getProtocol();
        System.out.println("protocol = " + protocol);
        String serverName = request.getServerName();
        System.out.println("serverName = " + serverName);
        int port = request.getServerPort();
        System.out.println("port = " + port);
        String servletPath = request.getServletPath();
        System.out.println("servletPath = " + servletPath);
        Map<String, String[]> map = request.getParameterMap();
        map.forEach((k,v)->{
            System.out.println(k+":"+ Arrays.toString(v));
        });
        Enumeration<String> names = request.getHeaderNames();
        while (names.hasMoreElements()){
            String name = names.nextElement();
            String value = request.getHeader(name);
            System.out.println(name +":"+value);
        }
        return  "中央五组";
    }


}
